/*
 * File: VEWM.c
 *
 * Code generated for Simulink model 'VEWM'.
 *
 * Model version                  : 3.391
 * Simulink Coder version         : 9.4 (R2020b) 29-Jul-2020
 * C/C++ source code generated on : Wed Feb 28 13:55:32 2024
 *
 * Target selection: ert.tlc
 * Embedded hardware selection: NXP->Cortex-M4
 * Code generation objective: MISRA C:2012 guidelines
 * Validation result: Not run
 */

#include "VEWM.h"
#include "VEWM_private.h"
#include "RTE.h"

/* Named constants for Chart: '<S5>/VEWMMgt' */
#define IN_AdhCheck                    ((uint8_T)1U)
#define IN_AdhCheck1                   ((uint8_T)2U)
#define IN_AdhCheck2                   ((uint8_T)3U)
#define IN_AdhCheck3                   ((uint8_T)4U)
#define IN_ChargePause                 ((uint8_T)1U)
#define IN_DChging                     ((uint8_T)1U)
#define IN_MaiRlyCls                   ((uint8_T)5U)
#define IN_MaiRlyCls4                  ((uint8_T)6U)
#define IN_MaiRlyCls5                  ((uint8_T)7U)
#define IN_NO_ACTIVE_CHILD             ((uint8_T)0U)
#define IN_PWR_DataWrtie               ((uint8_T)2U)
#define IN_PWR_Init                    ((uint8_T)3U)
#define IN_PWR_Init1                   ((uint8_T)4U)
#define IN_PWR_Init_d                  ((uint8_T)8U)
#define IN_PWR_SleepMode               ((uint8_T)5U)
#define IN_PWR_Standby                 ((uint8_T)6U)
#define IN_PosRlyPwrDown2              ((uint8_T)9U)
#define IN_PosRlyPwrDown3              ((uint8_T)10U)
#define IN_PosRlyPwrDownDelay          ((uint8_T)11U)
#define IN_PosRlyPwrDownDelay1         ((uint8_T)12U)
#define IN_PosRlyPwrDownDelay3         ((uint8_T)13U)
#define IN_PosRlyPwrDownDelay4         ((uint8_T)14U)
#define IN_PosRlyPwrDownDelay5         ((uint8_T)15U)
#define IN_PosRlyPwrDownDelay6         ((uint8_T)16U)
#define IN_PosRlyPwrDownDelay7         ((uint8_T)17U)
#define IN_PreChgCheck                 ((uint8_T)18U)
#define IN_PreChgCheck1                ((uint8_T)19U)
#define IN_PreChgCheck2                ((uint8_T)20U)
#define IN_PreRlyCls                   ((uint8_T)21U)
#define IN_PreRlyCls1                  ((uint8_T)22U)
#define IN_PreRlyCls2                  ((uint8_T)23U)
#define IN_PreRlyOpn                   ((uint8_T)24U)
#define IN_PwrDown                     ((uint8_T)25U)
#define IN_PwrDownDelay                ((uint8_T)26U)
#define IN_PwrDownDelay1               ((uint8_T)27U)
#define IN_PwrDownDelay2               ((uint8_T)28U)
#define IN_Pwr_AfterRun                ((uint8_T)7U)
#define IN_QChging                     ((uint8_T)8U)
#define IN_SChging                     ((uint8_T)9U)
#define IN_SchgMode                    ((uint8_T)29U)
#define IN_SchgMode1                   ((uint8_T)30U)
#define IN_SchgWorking                 ((uint8_T)2U)
#define IN_Step                        ((uint8_T)1U)
#define IN_Step1                       ((uint8_T)1U)
#define IN_Step1_i                     ((uint8_T)2U)
#define IN_Step2                       ((uint8_T)2U)
#define IN_Step3                       ((uint8_T)2U)
#define IN_Step3_c                     ((uint8_T)3U)
#define IN_Step4                       ((uint8_T)4U)
#define IN_wait                        ((uint8_T)3U)

/* Block signals (default storage) */
B_VEWM_T VEWM_B;

/* Block states (default storage) */
DW_VEWM_T VEWM_DW;

/* Real-time model */
static RT_MODEL_VEWM_T VEWM_M_;
RT_MODEL_VEWM_T *const VEWM_M = &VEWM_M_;

/* Exported data definition */

/* Definition for custom storage class: ExportToFile */
uint8_T vewm_enum_DisSts = ((uint8_T)0U);/* '<S5>/VEWMMgt' */

/* 放电流程状态(0:standby
   1:放电继电器闭合前粘连检测
   2:放电中
   3:继电器闭合失败
   4:故障请求下电
   5:下电完成) */
uint8_T vewm_enum_FastChgSts = ((uint8_T)0U);/* '<S5>/VEWMMgt' */

/* 快充流程状态(0:standby
   1:充电继电器粘连检测
   2:快充充电中
   3:充电终止
   4:满充状态
   5:CC丢失(拔枪)
   6:充电继电器闭合过程中
   7:充电加热中
   8:加热继电器粘连检测
   9:加热继电器闭合过程中) */
uint8_T vewm_enum_OCFltSts = ((uint8_T)0U);/* '<S5>/VEWMMgt' */

/* 过流故障状态(0:Invalid
   1:放电下电过流
   2:充电下电过流) */
uint8_T vewm_enum_PrechrgSts = ((uint8_T)0U);/* '<S5>/VEWMMgt' */

/* 预充状态(0:standby
   1:预充过程中
   2:预充完成
   3:预充失败) */
uint8_T vewm_enum_QChgReq = ((uint8_T)0U);/* '<S5>/VEWMMgt' */
uint8_T vewm_enum_SleepSt = ((uint8_T)0U);/* '<S5>/VEWMMgt' */

/* 可进入休眠状态(0:default
   1:请求休眠) */
uint8_T vewm_enum_SlowChgSts = ((uint8_T)0U);/* '<S5>/VEWMMgt' */

/* 慢充流程状态 */
uint8_T vewm_enum_keeptempdly = ((uint8_T)0U);/* '<S5>/VEWMMgt' */
uint8_T vewm_enum_socAlw = ((uint8_T)0U);/* '<S5>/VEWMMgt' */
uint8_T vewm_enum_workingMode = ((uint8_T)0U);/* '<S5>/VEWMMgt' */

/* 整车功能模式(0:Invalid
   1:Standby
   2:Discharging
   3:QuickCharging
   4:SlowCharging
   5:AfterRun
   6:PowerDownRequest
   7:SleepWait
   8:DataWrite
   9:Sleeping) */
boolean_T vewm_flg_PTCNegRlyCtr = false;/* '<S5>/Constant4' */

/* PTC负极继电器控制(0:open
   1:close) */
boolean_T vewm_flg_PTCRlyCtr = false;  /* '<S5>/Constant2' */

/* PTC继电器控制(0:open
   1:close) */
boolean_T vewm_flg_negRlyCtr = false;  /* '<S5>/Constant' */

/* 主负继电器控制(0:open
   1:close) */
boolean_T vewm_flg_posRlyCtr = false;  /* '<S5>/VEWMMgt' */

/* 主正继电器控制(0:open
   1:close) */
boolean_T vewm_flg_prechgRlyCtr = false;/* '<S5>/VEWMMgt' */

/* 预充继电器控制(0:open
   1:close) */
boolean_T vewm_flg_qchgNegRlyCtr = false;/* '<S5>/Constant3' */

/* 快充负极继电器控制(0:open
   1:close) */
boolean_T vewm_flg_qchgRlyCtr = false; /* '<S5>/Constant1' */

/* 快充继电器控制(0:open
   1:close) */
uint8_T vewm_flg_rechg = ((uint8_T)0U);/* '<S5>/VEWMMgt' */

/* Forward declaration for local functions */
static void SchgMode1(void);
static void AdhCheck(void);
static void AdhCheck2(void);
static void AdhCheck3(void);
static boolean_T IsVcuCtrlPwrOn(void);
static void PWR_Init(void);
static void PosRlyPwrDownDelay(void);
static void PosRlyPwrDownDelay1(void);
static void PreChgCheck1(void);
static void PreRlyOpn(void);
static void PwrDownDelay1(void);
static void PwrDownDelay2(void);
static void SchgMode(void);
static void DsgRlyPwrFlow(void);
static void WriteWorkMode(uint8_T mode);
static boolean_T waitms(uint16_T setms);
static boolean_T IsWorkModeAlw(uint8_T alwty);

/* Output and update for atomic system: '<S5>/CurrSub' */
void CurrSub(void)
{
    int16_T Abs;
    Abs = (int16_T)((int16_T)(Rte_ma_BatCurr_GetVal() / 1000U) - 1000);
    if (Abs > 1000)
    {
        Abs = 1000;
    }
    else
    {
        if (Abs < -1000)
        {
            Abs = -1000;
        }
    }

    if (Abs < 0)
    {
        Abs = (int16_T)-Abs;
    }

    VEWM_B.DataTypeConversion1 = (uint16_T)Abs;
}

/* Function for Chart: '<S5>/VEWMMgt' */
static void SchgMode1(void)
{
    boolean_T guard1 = false;
    guard1 = false;
    if (Rte_mv_CellMaxVol_GetVal() >= Pccfg_QChgMaxCellVolt)
    {
        vewm_enum_FastChgSts = 4U;
        vewm_enum_socAlw = 0U;
        guard1 = true;
    }
    else if ((Rte_vcan_HVPwrCmd_GetVal() == 0) || (!Rte_flg_QChgIgSts_GetVal()) ||
             (Rte_CANRx_QchgAlow_GetVal() == 0))
    {
        vewm_enum_FastChgSts = 6U;
        VEWM_DW.is_DsgRlyPwrFlow = IN_PosRlyPwrDownDelay6;
        VEWM_DW.Pos_cnt = 0U;
    }
    else if (tmsc_flg_MaiRlyPwrOn == 2)
    {
        vewm_enum_FastChgSts = 4U;
        VEWM_DW.keepTempFlg = 1U;
        vewm_enum_socAlw = 1U;
        guard1 = true;
    }
    else
    {
        if ((fltm_flg_ChgPwrDownFlt != 0) || (Rte_obc_FltSts_GetVal() != 0))
        {
            VEWM_DW.is_DsgRlyPwrFlow = IN_PosRlyPwrDownDelay7;
            VEWM_DW.Pos_cnt = 0U;
            vewm_enum_FastChgSts = 3U;
        }
    }

    if (guard1)
    {
        VEWM_DW.is_DsgRlyPwrFlow = IN_PwrDownDelay2;
        VEWM_DW.Pos_cnt = 0U;
    }
}

/* Function for Chart: '<S5>/VEWMMgt' */
static void AdhCheck(void)
{
    if ((Rte_vcan_HVPwrCmd_GetVal() == 0) || (fltm_flg_DsgPwrDownFlt != 0) ||
            VEWM_B.LogicalOperator)
    {
        VEWM_DW.is_DsgRlyPwrFlow = IN_PWR_Init_d;
        vewm_flg_posRlyCtr = false;
        vewm_enum_DisSts = 0U;
        vewm_enum_keeptempdly = 0U;
        VEWM_DW.mode = 0U;
        vewm_enum_QChgReq = 2U;
    }
    else if ((fltm_enum_adhChkSts == 1) && (!fltm_flg_hvilFlt))
    {
        VEWM_DW.Pwr_Cnt++;
        VEWM_DW.is_DsgRlyPwrFlow = IN_PreRlyCls;
        vewm_flg_prechgRlyCtr = true;
        vewm_enum_PrechrgSts = 1U;
        VEWM_DW.Pos_cnt = 0U;
    }
    else
    {
        VEWM_DW.Pos_cnt++;
    }
}

/* Function for Chart: '<S5>/VEWMMgt' */
static void AdhCheck2(void)
{
    if ((VEWM_DW.Pos_cnt > 10) && (!fltm_flg_hvilFlt))
    {
        VEWM_DW.is_DsgRlyPwrFlow = IN_PreRlyCls1;
        vewm_flg_prechgRlyCtr = true;
        vewm_enum_PrechrgSts = 1U;
        VEWM_DW.Pos_cnt = 0U;
    }
    else if ((Rte_vcan_HVPwrCmd_GetVal() == 0) || (fltm_flg_ChgPwrDownFlt != 0) ||
             (!VEWM_B.LogicalOperator) || (Rte_obc_FltSts_GetVal() != 0))
    {
        VEWM_DW.is_DsgRlyPwrFlow = IN_PWR_Init_d;
        vewm_flg_posRlyCtr = false;
        vewm_enum_DisSts = 0U;
        vewm_enum_keeptempdly = 0U;
        VEWM_DW.mode = 0U;
        vewm_enum_QChgReq = 2U;
    }
    else
    {
        VEWM_DW.Pos_cnt++;
    }
}

/* Function for Chart: '<S5>/VEWMMgt' */
static void AdhCheck3(void)
{
    vewm_enum_QChgReq = 1U;
    if ((Rte_vcan_HVPwrCmd_GetVal() == 0) || (fltm_flg_ChgPwrDownFlt != 0) ||
            (!Rte_flg_QChgIgSts_GetVal()) || (Rte_CANRx_QchgAlow_GetVal() == 0) ||
        (Rte_obc_FltSts_GetVal() != 0))
    {
        VEWM_DW.is_DsgRlyPwrFlow = IN_PWR_Init_d;
        vewm_flg_posRlyCtr = false;
        vewm_enum_DisSts = 0U;
        vewm_enum_keeptempdly = 0U;
        VEWM_DW.mode = 0U;
        vewm_enum_QChgReq = 2U;
    }
    else if ((VEWM_DW.Pos_cnt > 10) && (!fltm_flg_hvilFlt))
    {
        VEWM_DW.is_DsgRlyPwrFlow = IN_PreRlyCls2;
        vewm_flg_prechgRlyCtr = true;
        vewm_enum_PrechrgSts = 1U;
        VEWM_DW.Pos_cnt = 0U;
    }
    else
    {
        VEWM_DW.Pos_cnt++;
    }
}

/* Function for Chart: '<S5>/VEWMMgt' */
static boolean_T IsVcuCtrlPwrOn(void)
{
    return Rte_vcan_HVPwrCmd_GetVal() == ((uint8_T)Pdcfg_VcuCtrlPwrOn);
}

/* Function for Chart: '<S5>/VEWMMgt' */
static void PWR_Init(void)
{
    boolean_T tmp;
    boolean_T tmp_0;
    vewm_enum_keeptempdly = 0U;
    vewm_enum_QChgReq = 2U;
    tmp = IsVcuCtrlPwrOn();
    tmp_0 = !Rte_flg_QChgIgSts_GetVal();
    if ((vewm_enum_workingMode == ((uint8_T)Pdcfg_WmDsging)) && tmp &&
            (!VEWM_B.LogicalOperator) && tmp_0 && Rte_flg_IgSts_GetVal() &&
            (fltm_flg_DsgPwrDownFlt == 0) && (fltm_flg_ChgPwrDownFlt == 0))
    {
        VEWM_DW.mode = 1U;
        VEWM_DW.is_DsgRlyPwrFlow = IN_AdhCheck;
        vewm_enum_DisSts = 1U;
        vewm_enum_PrechrgSts = 0U;
        VEWM_DW.Pos_cnt = 0U;
    }
    else if ((vewm_enum_workingMode == ((uint8_T)Pdcfg_WmQChging)) && tmp &&
             Rte_flg_QChgIgSts_GetVal() && (Rte_CANRx_QchgAlow_GetVal() != 0) &&
             (fltm_flg_ChgPwrDownFlt == 0) && (Rte_obc_FltSts_GetVal() == 0) &&
             (Rte_mv_CellMinVol_GetVal() >= 1500))
    {
        VEWM_DW.mode = 3U;
        VEWM_DW.is_DsgRlyPwrFlow = IN_AdhCheck3;
        vewm_enum_FastChgSts = 1U;
        vewm_enum_QChgReq = 1U;
        VEWM_DW.Pos_cnt = 0U;
    }
    else
    {
        if ((vewm_enum_workingMode == ((uint8_T)Pdcfg_WmSChging)) && tmp &&
                VEWM_B.LogicalOperator && tmp_0 && (fltm_flg_ChgPwrDownFlt == 0)
            && (Rte_obc_FltSts_GetVal() == 0) && (Rte_mv_CellMinVol_GetVal() >=
                1500))
        {
            VEWM_DW.mode = 2U;
            VEWM_DW.is_DsgRlyPwrFlow = IN_AdhCheck2;
            vewm_enum_SlowChgSts = 1U;
            VEWM_DW.Pos_cnt = 0U;
        }
    }
}

/* Function for Chart: '<S5>/VEWMMgt' */
static void PosRlyPwrDownDelay(void)
{
    if ((fltm_flg_DsgPwrDownFlt == 0) && Rte_flg_IgSts_GetVal())
    {
        VEWM_DW.is_DsgRlyPwrFlow = IN_PreRlyOpn;
        vewm_flg_prechgRlyCtr = false;
        vewm_enum_DisSts = 2U;
    }
    else if (Rte_vcan_HVPwrCmd_GetVal() == 0)
    {
        VEWM_DW.is_DsgRlyPwrFlow = IN_PwrDownDelay;
        VEWM_DW.Pos_cnt = 0U;
    }
    else if ((VEWM_DW.Pos_cnt >= 1200) || (VEWM_B.LogicalOperator1 &&
              (VEWM_DW.Pos_cnt >= 300)))
    {
        VEWM_DW.is_DsgRlyPwrFlow = IN_PwrDown;
        vewm_flg_posRlyCtr = false;
        VEWM_DW.Pos_cnt = 0U;
        vewm_enum_DisSts = 6U;
    }
    else
    {
        VEWM_DW.Pos_cnt++;
    }
}

/* Function for Chart: '<S5>/VEWMMgt' */
static void PosRlyPwrDownDelay1(void)
{
    if ((fltm_flg_ChgPwrDownFlt == 0) && (Rte_obc_FltSts_GetVal() == 0))
    {
        VEWM_DW.is_DsgRlyPwrFlow = IN_SchgMode;
        VEWM_DW.is_SchgMode = IN_SchgWorking;
        VEWM_DW.keepTempFlg = 0U;
        vewm_enum_SlowChgSts = 2U;
        VEWM_DW.Pos_cnt = 0U;
    }
    else if (VEWM_DW.Pos_cnt >= 300)
    {
        VEWM_DW.is_DsgRlyPwrFlow = IN_PosRlyPwrDown2;
        vewm_flg_posRlyCtr = false;
        vewm_enum_keeptempdly = 0U;
        VEWM_DW.Pos_cnt = 0U;
    }
    else
    {
        VEWM_DW.Pos_cnt++;
    }
}

/* Function for Chart: '<S5>/VEWMMgt' */
static void PreChgCheck1(void)
{
    vewm_enum_PrechrgSts = 3U;
    vewm_enum_SlowChgSts = 9U;
    VEWM_DW.is_DsgRlyPwrFlow = IN_PwrDownDelay1;
    VEWM_DW.Pos_cnt = 0U;
    vewm_enum_keeptempdly = 1U;
}

/* Function for Chart: '<S5>/VEWMMgt' */
static void PreRlyOpn(void)
{
    if ((Rte_vcan_HVPwrCmd_GetVal() != 0) && Rte_flg_QChgIgSts_GetVal() &&
            (fltm_flg_ChgPwrDownFlt == 0) && (Rte_obc_FltSts_GetVal() == 0))
    {
        vewm_enum_DisSts = 6U;
        VEWM_DW.is_DsgRlyPwrFlow = IN_SchgMode1;
        VEWM_DW.keepTempFlg = 0U;
        vewm_enum_FastChgSts = 2U;

        /* Pos_cnt = 0; */
    }
    else if (Rte_vcan_HVPwrCmd_GetVal() == 0)
    {
        VEWM_DW.is_DsgRlyPwrFlow = IN_PosRlyPwrDownDelay4;
        VEWM_DW.Pos_cnt = 0U;
    }
    else if ((Rte_vcan_HVPwrCmd_GetVal() != 0) && VEWM_B.LogicalOperator &&
             (fltm_flg_ChgPwrDownFlt == 0) && (Rte_obc_FltSts_GetVal() == 0))
    {
        vewm_enum_DisSts = 5U;
        VEWM_DW.is_DsgRlyPwrFlow = IN_SchgMode;
        VEWM_DW.is_SchgMode = IN_SchgWorking;
        VEWM_DW.keepTempFlg = 0U;
        vewm_enum_SlowChgSts = 2U;
        VEWM_DW.Pos_cnt = 0U;
    }
    else if ((fltm_flg_DsgPwrDownFlt != 0) || (!Rte_flg_IgSts_GetVal()))
    {
        VEWM_DW.is_DsgRlyPwrFlow = IN_PosRlyPwrDownDelay;
        VEWM_DW.Pos_cnt = 0U;
        vewm_enum_DisSts = 3U;
    }
    else
    {
        if (!Rte_flg_IgSts_GetVal())
        {
            VEWM_DW.is_DsgRlyPwrFlow = IN_PosRlyPwrDownDelay3;
            VEWM_DW.Pos_cnt = 0U;
        }
    }
}

/* Function for Chart: '<S5>/VEWMMgt' */
static void PwrDownDelay1(void)
{
    boolean_T guard1 = false;
    boolean_T guard2 = false;
    vewm_enum_keeptempdly = 1U;
    guard1 = false;
    guard2 = false;
    if (Rte_vcan_HVPwrCmd_GetVal() == 0)
    {
        guard1 = true;
    }
    else if ((vewm_enum_SlowChgSts == 6) && VEWM_B.LogicalOperator &&
             (Rte_vcan_HVPwrCmd_GetVal() != 0) && (fltm_flg_ChgPwrDownFlt == 0) &&
             (Rte_obc_FltSts_GetVal() == 0))
    {
        guard2 = true;
    }
    else if ((Rte_vcan_HVPwrCmd_GetVal() != 0) && (!VEWM_B.LogicalOperator) &&
             (Rte_enum_SChgCcSts_GetVal() == 0) && Rte_flg_IgSts_GetVal() &&
             (fltm_flg_DsgPwrDownFlt == 0) && (VEWM_DW.Pos_cnt > 100))
    {
        vewm_enum_SlowChgSts = 5U;
        VEWM_DW.is_DsgRlyPwrFlow = IN_PreRlyOpn;
        vewm_flg_prechgRlyCtr = false;
        vewm_enum_DisSts = 2U;
    }
    else if ((vewm_enum_SlowChgSts == 4) && (soce_pct_SOC <= 9900) &&
             (VEWM_DW.Pos_cnt >= 200) && VEWM_B.LogicalOperator &&
             (Rte_vcan_HVPwrCmd_GetVal() != 0))
    {
        vewm_flg_rechg = 1U;
        guard2 = true;
    }
    else if ((!vewm_flg_posRlyCtr) || (((fltm_flg_ChgPwrDownFlt != 0) ||
               (fltm_flg_DsgPwrDownFlt != 0)) && (VEWM_DW.Pos_cnt > 300)))
    {
        guard1 = true;
    }
    else if ((tmsc_enum_HeatSts == 5) && (VEWM_DW.Pos_cnt >= 200) &&
             VEWM_B.LogicalOperator && (Rte_vcan_HVPwrCmd_GetVal() != 0))
    {
        guard2 = true;
    }
    else
    {
        VEWM_DW.Pos_cnt++;
    }

    if (guard2)
    {
        VEWM_DW.is_DsgRlyPwrFlow = IN_SchgMode;
        VEWM_DW.is_SchgMode = IN_SchgWorking;
        VEWM_DW.keepTempFlg = 0U;
        vewm_enum_SlowChgSts = 2U;
        VEWM_DW.Pos_cnt = 0U;
    }

    if (guard1)
    {
        VEWM_DW.is_DsgRlyPwrFlow = IN_PosRlyPwrDown2;
        vewm_flg_posRlyCtr = false;
        vewm_enum_keeptempdly = 0U;
        VEWM_DW.Pos_cnt = 0U;
    }
}

/* Function for Chart: '<S5>/VEWMMgt' */
static void PwrDownDelay2(void)
{
    boolean_T guard1 = false;
    boolean_T guard2 = false;
    guard1 = false;
    guard2 = false;
    if (Rte_vcan_HVPwrCmd_GetVal() == 0)
    {
        guard1 = true;
    }
    else if ((vewm_enum_FastChgSts == 6) && Rte_flg_QChgIgSts_GetVal() &&
             (Rte_vcan_HVPwrCmd_GetVal() != 0) && (fltm_flg_ChgPwrDownFlt == 0) &&
             (Rte_obc_FltSts_GetVal() == 0))
    {
        guard2 = true;
    }
    else if ((Rte_vcan_HVPwrCmd_GetVal() != 0) && (!Rte_flg_QChgIgSts_GetVal()) &&
             Rte_flg_IgSts_GetVal() && (fltm_flg_DsgPwrDownFlt == 0) &&
             (VEWM_DW.Pos_cnt > 100))
    {
        vewm_enum_FastChgSts = 6U;
        VEWM_DW.is_DsgRlyPwrFlow = IN_PreRlyOpn;
        vewm_flg_prechgRlyCtr = false;
        vewm_enum_DisSts = 2U;
    }
    else if (((tmsc_enum_HeatSts == 5) || ((vewm_enum_FastChgSts == 4) &&
               (soce_pct_SOC <= 9900))) && (VEWM_DW.Pos_cnt >= 200) &&
             Rte_flg_QChgIgSts_GetVal() && (Rte_vcan_HVPwrCmd_GetVal() != 0))
    {
        guard2 = true;
    }
    else if ((!vewm_flg_posRlyCtr) || (((fltm_flg_ChgPwrDownFlt != 0) ||
               (fltm_flg_DsgPwrDownFlt != 0)) && (VEWM_DW.Pos_cnt > 300)))
    {
        guard1 = true;
    }
    else
    {
        VEWM_DW.Pos_cnt++;
    }

    if (guard2)
    {
        VEWM_DW.is_DsgRlyPwrFlow = IN_SchgMode1;
        VEWM_DW.keepTempFlg = 0U;
        vewm_enum_FastChgSts = 2U;

        /* Pos_cnt = 0; */
    }

    if (guard1)
    {
        VEWM_DW.is_DsgRlyPwrFlow = IN_PosRlyPwrDown3;
        vewm_flg_posRlyCtr = false;
        VEWM_DW.Pos_cnt = 0U;
    }
}

/* Function for Chart: '<S5>/VEWMMgt' */
static void SchgMode(void)
{
    boolean_T guard1 = false;
    if ((Rte_vcan_HVPwrCmd_GetVal() == 0) || (!VEWM_B.LogicalOperator))
    {
        vewm_enum_SlowChgSts = 6U;
        VEWM_DW.is_SchgMode = IN_NO_ACTIVE_CHILD;
        VEWM_DW.is_DsgRlyPwrFlow = IN_PosRlyPwrDownDelay5;
        VEWM_DW.Pos_cnt = 0U;
    }
    else
    {
        guard1 = false;
        if (Rte_mv_CellMaxVol_GetVal() >= Pccfg_SChgMaxCellVolt)
        {
            vewm_enum_SlowChgSts = 4U;
            vewm_enum_socAlw = 0U;
            vewm_flg_rechg = 0U;
            guard1 = true;
        }
        else if ((fltm_flg_ChgPwrDownFlt != 0) || (Rte_obc_FltSts_GetVal() != 0))
        {
            VEWM_DW.is_SchgMode = IN_NO_ACTIVE_CHILD;
            VEWM_DW.is_DsgRlyPwrFlow = IN_PosRlyPwrDownDelay1;
            VEWM_DW.Pos_cnt = 0U;
            vewm_enum_SlowChgSts = 3U;
        }
        else if (tmsc_flg_MaiRlyPwrOn == 2)
        {
            vewm_enum_SlowChgSts = 4U;
            VEWM_DW.keepTempFlg = 1U;
            vewm_enum_socAlw = 1U;
            guard1 = true;
        }
        else if (VEWM_DW.is_SchgMode == IN_ChargePause)
        {
            if (tmsc_flg_MaiRlyPwrOn == 1)
            {
                VEWM_DW.is_SchgMode = IN_NO_ACTIVE_CHILD;
                VEWM_DW.is_DsgRlyPwrFlow = IN_PWR_Init_d;
                vewm_flg_posRlyCtr = false;
                vewm_enum_DisSts = 0U;
                vewm_enum_keeptempdly = 0U;
                VEWM_DW.mode = 0U;
                vewm_enum_QChgReq = 2U;
            }
        }
        else
        {
            /* case IN_SchgWorking: */
            if ((tmsc_enum_HeatSts == 2) && (VEWM_DW.Pos_cnt >= 200))
            {
                VEWM_DW.is_SchgMode = IN_ChargePause;
                vewm_flg_posRlyCtr = false;
            }
            else
            {
                if (tmsc_enum_HeatSts == 2)
                {
                    VEWM_DW.Pos_cnt++;
                }
            }
        }

        if (guard1)
        {
            VEWM_DW.is_SchgMode = IN_NO_ACTIVE_CHILD;
            VEWM_DW.is_DsgRlyPwrFlow = IN_PwrDownDelay1;
            VEWM_DW.Pos_cnt = 0U;
            vewm_enum_keeptempdly = 1U;
        }
    }
}

/* Function for Chart: '<S5>/VEWMMgt' */
static void DsgRlyPwrFlow(void)
{
    boolean_T guard1 = false;
    guard1 = false;
    switch (VEWM_DW.is_DsgRlyPwrFlow)
    {
      case IN_AdhCheck:
        AdhCheck();
        break;

      case IN_AdhCheck1:
        break;

      case IN_AdhCheck2:
        AdhCheck2();
        break;

      case IN_AdhCheck3:
        AdhCheck3();
        break;

      case IN_MaiRlyCls:
        if (VEWM_DW.Pos_cnt > 15)
        {
            VEWM_DW.is_DsgRlyPwrFlow = IN_PreRlyOpn;
            vewm_flg_prechgRlyCtr = false;
            vewm_enum_DisSts = 2U;
        }
        else
        {
            VEWM_DW.Pos_cnt++;
        }
        break;

      case IN_MaiRlyCls4:
        if (VEWM_DW.Pos_cnt > 10)
        {
            vewm_flg_prechgRlyCtr = false;
            VEWM_DW.is_DsgRlyPwrFlow = IN_SchgMode;
            VEWM_DW.is_SchgMode = IN_SchgWorking;
            VEWM_DW.keepTempFlg = 0U;
            vewm_enum_SlowChgSts = 2U;
            VEWM_DW.Pos_cnt = 0U;
        }
        else
        {
            VEWM_DW.Pos_cnt++;
        }
        break;

      case IN_MaiRlyCls5:
        if (VEWM_DW.Pos_cnt > 10)
        {
            vewm_flg_prechgRlyCtr = false;
            VEWM_DW.is_DsgRlyPwrFlow = IN_SchgMode1;
            VEWM_DW.keepTempFlg = 0U;
            vewm_enum_FastChgSts = 2U;

            /* Pos_cnt = 0; */
        }
        else
        {
            VEWM_DW.Pos_cnt++;
        }
        break;

      case IN_PWR_Init_d:
        PWR_Init();
        break;

      case IN_PosRlyPwrDown2:
        vewm_enum_keeptempdly = 0U;
        if (VEWM_DW.Pos_cnt >= 100)
        {
            VEWM_DW.MaiRly_Cutoff = 1U;
            VEWM_DW.is_DsgRlyPwrFlow = IN_PWR_Init_d;
            vewm_flg_posRlyCtr = false;
            vewm_enum_DisSts = 0U;
            vewm_enum_keeptempdly = 0U;
            VEWM_DW.mode = 0U;
            vewm_enum_QChgReq = 2U;
        }
        else
        {
            VEWM_DW.Pos_cnt++;
        }
        break;

      case IN_PosRlyPwrDown3:
        if (VEWM_DW.Pos_cnt >= 100)
        {
            VEWM_DW.MaiRly_Cutoff = 1U;
            VEWM_DW.is_DsgRlyPwrFlow = IN_PWR_Init_d;
            vewm_flg_posRlyCtr = false;
            vewm_enum_DisSts = 0U;
            vewm_enum_keeptempdly = 0U;
            VEWM_DW.mode = 0U;
            vewm_enum_QChgReq = 2U;
        }
        else
        {
            VEWM_DW.Pos_cnt++;
        }
        break;

      case IN_PosRlyPwrDownDelay:
        PosRlyPwrDownDelay();
        break;

      case IN_PosRlyPwrDownDelay1:
        PosRlyPwrDownDelay1();
        break;

      case IN_PosRlyPwrDownDelay3:
        if (Rte_flg_IgSts_GetVal() || VEWM_B.LogicalOperator)
        {
            VEWM_DW.is_DsgRlyPwrFlow = IN_PreRlyOpn;
            vewm_flg_prechgRlyCtr = false;
            vewm_enum_DisSts = 2U;
        }
        else if (VEWM_DW.Pos_cnt >= 300)
        {
            VEWM_DW.is_DsgRlyPwrFlow = IN_PwrDownDelay;
            VEWM_DW.Pos_cnt = 0U;
        }
        else
        {
            VEWM_DW.Pos_cnt++;
        }
        break;

      case IN_PosRlyPwrDownDelay4:
        if (Rte_vcan_HVPwrCmd_GetVal() != 0)
        {
            VEWM_DW.is_DsgRlyPwrFlow = IN_PreRlyOpn;
            vewm_flg_prechgRlyCtr = false;
            vewm_enum_DisSts = 2U;
        }
        else if (VEWM_DW.Pos_cnt >= 40)
        {
            VEWM_DW.is_DsgRlyPwrFlow = IN_PwrDownDelay;
            VEWM_DW.Pos_cnt = 0U;
        }
        else
        {
            VEWM_DW.Pos_cnt++;
        }
        break;

      case IN_PosRlyPwrDownDelay5:
        if ((Rte_vcan_HVPwrCmd_GetVal() != 0) && VEWM_B.LogicalOperator)
        {
            VEWM_DW.is_DsgRlyPwrFlow = IN_SchgMode;
            VEWM_DW.is_SchgMode = IN_SchgWorking;
            VEWM_DW.keepTempFlg = 0U;
            vewm_enum_SlowChgSts = 2U;
            VEWM_DW.Pos_cnt = 0U;
        }
        else if (VEWM_DW.Pos_cnt >= 30)
        {
            VEWM_DW.is_DsgRlyPwrFlow = IN_PwrDownDelay1;
            VEWM_DW.Pos_cnt = 0U;
            vewm_enum_keeptempdly = 1U;
        }
        else
        {
            VEWM_DW.Pos_cnt++;
        }
        break;

      case IN_PosRlyPwrDownDelay6:
        if ((Rte_vcan_HVPwrCmd_GetVal() != 0) && Rte_flg_QChgIgSts_GetVal())
        {
            VEWM_DW.is_DsgRlyPwrFlow = IN_SchgMode1;
            VEWM_DW.keepTempFlg = 0U;
            vewm_enum_FastChgSts = 2U;

            /* Pos_cnt = 0; */
        }
        else if (VEWM_DW.Pos_cnt >= 30)
        {
            VEWM_DW.is_DsgRlyPwrFlow = IN_PwrDownDelay2;
            VEWM_DW.Pos_cnt = 0U;
        }
        else
        {
            VEWM_DW.Pos_cnt++;
        }
        break;

      case IN_PosRlyPwrDownDelay7:
        if ((fltm_flg_ChgPwrDownFlt == 0) && (Rte_obc_FltSts_GetVal() == 0))
        {
            VEWM_DW.is_DsgRlyPwrFlow = IN_SchgMode1;
            VEWM_DW.keepTempFlg = 0U;
            vewm_enum_FastChgSts = 2U;

            /* Pos_cnt = 0; */
        }
        else if (VEWM_DW.Pos_cnt >= 300)
        {
            VEWM_DW.is_DsgRlyPwrFlow = IN_PosRlyPwrDown3;
            vewm_flg_posRlyCtr = false;
            VEWM_DW.Pos_cnt = 0U;
        }
        else
        {
            VEWM_DW.Pos_cnt++;
        }
        break;

      case IN_PreChgCheck:
        if (VEWM_DW.Pos_cnt > 50)
        {
            VEWM_DW.is_DsgRlyPwrFlow = IN_PreRlyCls;
            vewm_flg_prechgRlyCtr = true;
            vewm_enum_PrechrgSts = 1U;
            VEWM_DW.Pos_cnt = 0U;
        }
        else
        {
            vewm_enum_PrechrgSts = 3U;
            VEWM_DW.is_DsgRlyPwrFlow = IN_AdhCheck1;
            vewm_enum_DisSts = 3U;
            VEWM_DW.MaiRly_Cutoff = 1U;
        }
        break;

      case IN_PreChgCheck1:
        PreChgCheck1();
        break;

      case IN_PreChgCheck2:
        vewm_enum_PrechrgSts = 3U;
        vewm_enum_FastChgSts = 9U;
        VEWM_DW.is_DsgRlyPwrFlow = IN_PwrDownDelay2;
        VEWM_DW.Pos_cnt = 0U;
        break;

      case IN_PreRlyCls:
        if (VEWM_DW.Pos_cnt > 150)
        {
            VEWM_DW.is_DsgRlyPwrFlow = IN_PreChgCheck;
            vewm_flg_prechgRlyCtr = false;
            VEWM_DW.Pos_cnt = 0U;
            VEWM_DW.prechg_cnt++;
        }
        else if (((uint32_T)((int32_T)Rte_mv_VLink_GetVal() * 100) > (uint32_T)
                  ((int32_T)Rte_mv_PackVolt_GetVal() * 90)) && (VEWM_DW.Pos_cnt >
                  50))
        {
            VEWM_DW.is_DsgRlyPwrFlow = IN_MaiRlyCls;
            vewm_flg_posRlyCtr = true;
            vewm_enum_PrechrgSts = 2U;
            VEWM_DW.Pos_cnt = 0U;
        }
        else
        {
            VEWM_DW.Pos_cnt++;
        }
        break;

      case IN_PreRlyCls1:
        if (VEWM_DW.Pos_cnt > 150)
        {
            VEWM_DW.is_DsgRlyPwrFlow = IN_PreChgCheck1;
            vewm_flg_prechgRlyCtr = false;
            VEWM_DW.Pos_cnt = 0U;
            VEWM_DW.prechg_cnt++;
        }
        else if (((uint32_T)((int32_T)Rte_mv_VLink_GetVal() * 100) > (uint32_T)
                  ((int32_T)Rte_mv_PackVolt_GetVal() * 90)) && (VEWM_DW.Pos_cnt >
                  50))
        {
            VEWM_DW.is_DsgRlyPwrFlow = IN_MaiRlyCls4;
            vewm_flg_posRlyCtr = true;
            vewm_enum_PrechrgSts = 2U;
            VEWM_DW.Pos_cnt = 0U;
        }
        else
        {
            VEWM_DW.Pos_cnt++;
        }
        break;

      case IN_PreRlyCls2:
        if (VEWM_DW.Pos_cnt > 150)
        {
            VEWM_DW.is_DsgRlyPwrFlow = IN_PreChgCheck2;
            vewm_flg_prechgRlyCtr = false;
            VEWM_DW.Pos_cnt = 0U;
            VEWM_DW.prechg_cnt++;
        }
        else if (((uint32_T)((int32_T)Rte_mv_VLink_GetVal() * 100) > (uint32_T)
                  ((int32_T)Rte_mv_PackVolt_GetVal() * 90)) && (VEWM_DW.Pos_cnt >
                  50))
        {
            VEWM_DW.is_DsgRlyPwrFlow = IN_MaiRlyCls5;
            vewm_flg_posRlyCtr = true;
            vewm_enum_PrechrgSts = 2U;
            VEWM_DW.Pos_cnt = 0U;
        }
        else
        {
            VEWM_DW.Pos_cnt++;
        }
        break;

      case IN_PreRlyOpn:
        PreRlyOpn();
        break;

      case IN_PwrDown:
        if (VEWM_DW.Pos_cnt >= 100)
        {
            VEWM_DW.MaiRly_Cutoff = 1U;
            VEWM_DW.is_DsgRlyPwrFlow = IN_PWR_Init_d;
            vewm_flg_posRlyCtr = false;
            vewm_enum_DisSts = 0U;
            vewm_enum_keeptempdly = 0U;
            VEWM_DW.mode = 0U;
            vewm_enum_QChgReq = 2U;
        }
        else
        {
            VEWM_DW.Pos_cnt++;
        }
        break;

      case IN_PwrDownDelay:
        if (VEWM_B.DataTypeConversion1 < 6)
        {
            guard1 = true;
        }
        else if (VEWM_DW.Pos_cnt > 300)
        {
            vewm_enum_OCFltSts = 1U;
            guard1 = true;
        }
        else
        {
            VEWM_DW.Pos_cnt++;
        }
        break;

      case IN_PwrDownDelay1:
        PwrDownDelay1();
        break;

      case IN_PwrDownDelay2:
        PwrDownDelay2();
        break;

      case IN_SchgMode:
        SchgMode();
        break;

      default:
        /* case IN_SchgMode1: */
        SchgMode1();
        break;
    }

    if (guard1)
    {
        VEWM_DW.is_DsgRlyPwrFlow = IN_PwrDown;
        vewm_flg_posRlyCtr = false;
        VEWM_DW.Pos_cnt = 0U;
        vewm_enum_DisSts = 6U;
    }
}

/* Function for Chart: '<S5>/VEWMMgt' */
static void WriteWorkMode(uint8_T mode)
{
    vewm_enum_workingMode = mode;
}

/* Function for Chart: '<S5>/VEWMMgt' */
static boolean_T waitms(uint16_T setms)
{
    boolean_T st;
    VEWM_DW.count++;
    if (VEWM_DW.count >= (int32_T)(setms / 10U))
    {
        st = true;
        VEWM_DW.count = 0U;
    }
    else
    {
        st = false;
    }

    return st;
}

/* Function for Chart: '<S5>/VEWMMgt' */
static boolean_T IsWorkModeAlw(uint8_T alwty)
{
    boolean_T res;
    if (alwty == ((uint8_T)Pdcfg_WmDsging))
    {
        res = false;
        if (Rte_flg_IgSts_GetVal() && (!VEWM_B.LogicalOperator) &&
                (!Rte_flg_QChgIgSts_GetVal()) && (fltm_flg_DsgPwrDownFlt == 0))
        {
            VEWM_DW.mode_cnt1++;
            if (VEWM_DW.mode_cnt1 > 8)
            {
                res = true;
                VEWM_DW.mode_cnt1 = 0U;
            }
        }
        else
        {
            VEWM_DW.mode_cnt1 = 0U;
        }
    }
    else if (alwty == ((uint8_T)Pdcfg_WmSChging))
    {
        res = false;
        if (VEWM_B.LogicalOperator && (!Rte_flg_QChgIgSts_GetVal()) &&
                (fltm_flg_ChgPwrDownFlt == 0) && (((vewm_enum_SlowChgSts != 4) &&
              (soce_pct_SOC < 9950) && (VEWM_DW.keepTempFlg == 0)) ||
                (tmsc_enum_HeatSts == 5)))
        {
            VEWM_DW.mode_cnt2++;
            if (VEWM_DW.mode_cnt2 > 10)
            {
                res = true;
                VEWM_DW.mode_cnt2 = 0U;
            }
        }
        else
        {
            VEWM_DW.mode_cnt2 = 0U;
        }
    }
    else if (alwty == ((uint8_T)Pdcfg_WmQChging))
    {
        res = false;
        if (Rte_flg_QChgIgSts_GetVal() && (fltm_flg_ChgPwrDownFlt == 0) &&
                (vewm_enum_FastChgSts != 4))
        {
            VEWM_DW.mode_cnt3++;
            if (VEWM_DW.mode_cnt3 > 10)
            {
                res = true;
                VEWM_DW.mode_cnt3 = 0U;
            }
        }
        else
        {
            VEWM_DW.mode_cnt3 = 0U;
        }
    }
    else
    {
        res = false;
    }

    return res;
}

/* Output and update for atomic system: '<S5>/VEWMMgt' */
void VEWMMgt(void)
{
    if (VEWM_DW.is_active_c4_VEWM == 0U)
    {
        VEWM_DW.is_active_c4_VEWM = 1U;
        VEWM_DW.is_DsgRlyPwrFlow = IN_PWR_Init_d;
        vewm_flg_posRlyCtr = false;
        vewm_enum_DisSts = 0U;
        vewm_enum_keeptempdly = 0U;
        VEWM_DW.mode = 0U;
        vewm_enum_QChgReq = 2U;
        VEWM_DW.is_WEWMFlow = IN_PWR_Init1;
        vewm_enum_SlowChgSts = 0U;

        /*  清慢充状态位 */
        vewm_enum_FastChgSts = 0U;
        vewm_enum_OCFltSts = 0U;
        VEWM_DW.Pwr_Cnt = 0U;
        vewm_enum_PrechrgSts = 0U;
        VEWM_DW.is_SlowChgFshClear1 = IN_Step;
        VEWM_DW.cnt = 0U;
        VEWM_DW.is_SlowChgFshClear = IN_Step;
        VEWM_DW.cnt1 = 0U;
    }
    else
    {
        DsgRlyPwrFlow();
        switch (VEWM_DW.is_WEWMFlow)
        {
          case IN_DChging:
            if ((VEWM_DW.MaiRly_Cutoff != 0) || (((!Rte_flg_IgSts_GetVal()) ||
                    Rte_flg_QChgIgSts_GetVal() || VEWM_B.LogicalOperator) &&
                    (VEWM_DW.mode == 0)))
            {
                VEWM_DW.is_WEWMFlow = IN_PWR_Standby;
                VEWM_DW.MaiRly_Cutoff = 0U;
            }
            else if (vewm_enum_DisSts == 6)
            {
                VEWM_DW.is_WEWMFlow = IN_QChging;
                WriteWorkMode(((uint8_T)Pdcfg_WmQChging));
            }
            else
            {
                if (vewm_enum_DisSts == 5)
                {
                    VEWM_DW.is_WEWMFlow = IN_SChging;
                    WriteWorkMode(((uint8_T)Pdcfg_WmSChging));
                }
            }
            break;

          case IN_PWR_DataWrtie:
            if (waitms(250))
            {
                VEWM_DW.is_WEWMFlow = IN_PWR_SleepMode;
                vewm_enum_SleepSt = 1U;
                WriteWorkMode(((uint8_T)Pdcfg_WmSleeping));
            }
            else
            {
                WriteWorkMode(((uint8_T)Pdcfg_WmDataWrite));
            }
            break;

          case IN_PWR_Init:
            vewm_enum_SleepSt = 0U;
            if (fltm_enum_SelfChkSts == 1)
            {
                VEWM_DW.is_WEWMFlow = IN_PWR_Standby;
                VEWM_DW.MaiRly_Cutoff = 0U;
            }
            else
            {
                if (!Rte_flg_FinIgSts_GetVal())
                {
                    VEWM_DW.is_WEWMFlow = IN_PWR_SleepMode;
                    vewm_enum_SleepSt = 1U;
                    WriteWorkMode(((uint8_T)Pdcfg_WmSleeping));
                }
            }
            break;

          case IN_PWR_Init1:
            VEWM_DW.is_WEWMFlow = IN_PWR_Init;
            vewm_enum_SleepSt = 0U;
            vewm_enum_DisSts = 0U;
            WriteWorkMode(((uint8_T)Pdcfg_WmInvalid));
            break;

          case IN_PWR_SleepMode:
            vewm_enum_SleepSt = 1U;
            if (Rte_flg_FinIgSts_GetVal())
            {
                VEWM_DW.is_WEWMFlow = IN_PWR_Init;
                vewm_enum_SleepSt = 0U;
                vewm_enum_DisSts = 0U;
                WriteWorkMode(((uint8_T)Pdcfg_WmInvalid));
            }
            break;

          case IN_PWR_Standby:
            if (!Rte_flg_FinIgSts_GetVal())
            {
                VEWM_DW.is_WEWMFlow = IN_Pwr_AfterRun;
                VEWM_DW.count = 0U;
            }
            else if (IsWorkModeAlw(((uint8_T)Pdcfg_WmDsging)) && IsVcuCtrlPwrOn()
                     && (!VEWM_B.LogicalOperator))
            {
                VEWM_DW.is_WEWMFlow = IN_DChging;
                WriteWorkMode(((uint8_T)Pdcfg_WmDsging));
            }
            else if (IsWorkModeAlw(((uint8_T)Pdcfg_WmSChging)))
            {
                VEWM_DW.is_WEWMFlow = IN_SChging;
                WriteWorkMode(((uint8_T)Pdcfg_WmSChging));
            }
            else if (IsWorkModeAlw(((uint8_T)Pdcfg_WmQChging)))
            {
                VEWM_DW.is_WEWMFlow = IN_QChging;
                WriteWorkMode(((uint8_T)Pdcfg_WmQChging));
            }
            else
            {
                WriteWorkMode(((uint8_T)Pdcfg_WmStandby));
            }
            break;

          case IN_Pwr_AfterRun:
            if (Rte_flg_FinIgSts_GetVal())
            {
                VEWM_DW.is_WEWMFlow = IN_PWR_Standby;
                VEWM_DW.MaiRly_Cutoff = 0U;
            }
            else if (waitms(250))
            {
                VEWM_DW.is_WEWMFlow = IN_PWR_DataWrtie;
                VEWM_DW.count = 0U;
            }
            else
            {
                WriteWorkMode(((uint8_T)Pdcfg_WmAfterRun));
            }
            break;

          case IN_QChging:
            if ((VEWM_DW.MaiRly_Cutoff != 0) || ((!Rte_flg_QChgIgSts_GetVal()) &&
                 (VEWM_DW.mode == 0)))
            {
                VEWM_DW.is_WEWMFlow = IN_PWR_Standby;
                VEWM_DW.MaiRly_Cutoff = 0U;
            }
            else
            {
                if (vewm_enum_FastChgSts == 6)
                {
                    VEWM_DW.is_WEWMFlow = IN_DChging;
                    WriteWorkMode(((uint8_T)Pdcfg_WmDsging));
                }
            }
            break;

          default:
            /* case IN_SChging: */
            if ((VEWM_DW.MaiRly_Cutoff != 0) || (((!VEWM_B.LogicalOperator) ||
                    Rte_flg_QChgIgSts_GetVal()) && (VEWM_DW.mode == 0)))
            {
                VEWM_DW.is_WEWMFlow = IN_PWR_Standby;
                VEWM_DW.MaiRly_Cutoff = 0U;
            }
            else
            {
                if (vewm_enum_SlowChgSts == 5)
                {
                    VEWM_DW.is_WEWMFlow = IN_DChging;
                    WriteWorkMode(((uint8_T)Pdcfg_WmDsging));
                }
            }
            break;
        }

        switch (VEWM_DW.is_SlowChgFshClear1)
        {
          case IN_Step:
            if (vewm_enum_SlowChgSts == 4)
            {
                VEWM_DW.is_SlowChgFshClear1 = IN_Step1_i;
            }
            break;

          case IN_Step1_i:
            if (!VEWM_B.LogicalOperator)
            {
                VEWM_DW.is_SlowChgFshClear1 = IN_Step4;
                VEWM_DW.cnt = 0U;
            }
            break;

          case IN_Step3_c:
            VEWM_DW.is_SlowChgFshClear1 = IN_Step;
            VEWM_DW.cnt = 0U;
            break;

          default:
            /* case IN_Step4: */
            if (VEWM_B.LogicalOperator)
            {
                VEWM_DW.is_SlowChgFshClear1 = IN_Step1_i;
            }
            else if (VEWM_DW.cnt > 100)
            {
                VEWM_DW.is_SlowChgFshClear1 = IN_Step3_c;
                vewm_enum_SlowChgSts = 0U;
                VEWM_DW.keepTempFlg = 0U;
            }
            else
            {
                VEWM_DW.cnt++;
            }
            break;
        }

        switch (VEWM_DW.is_SlowChgFshClear)
        {
          case IN_Step:
            if (vewm_enum_SlowChgSts == 4)
            {
                VEWM_DW.is_SlowChgFshClear = IN_wait;
                VEWM_DW.is_wait = IN_Step1;
            }
            break;

          case IN_Step3:
            VEWM_DW.is_SlowChgFshClear = IN_Step;
            VEWM_DW.cnt1 = 0U;
            break;

          default:
            /* case IN_wait: */
            if (vewm_enum_SlowChgSts != 4)
            {
                VEWM_DW.is_wait = IN_NO_ACTIVE_CHILD;
                VEWM_DW.is_SlowChgFshClear = IN_Step;
                VEWM_DW.cnt1 = 0U;
            }
            else if (VEWM_DW.cnt1 > 1000)
            {
                VEWM_DW.is_wait = IN_NO_ACTIVE_CHILD;
                VEWM_DW.is_SlowChgFshClear = IN_Step3;
                vewm_enum_socAlw = 1U;
            }
            else if (VEWM_DW.is_wait == IN_Step1)
            {
                VEWM_DW.is_wait = IN_Step2;
            }
            else
            {
                /* case IN_Step2: */
                VEWM_DW.cnt1++;
            }
            break;
        }
    }
}

/* System initialize for function-call system: '<S2>/VEWM' */
void VEWM_Init(void)
{
    vewm_flg_negRlyCtr = VEWM_ConstB.Constant;
    vewm_flg_qchgRlyCtr = VEWM_ConstB.Constant1;
    vewm_flg_PTCRlyCtr = VEWM_ConstB.Constant2;
    vewm_flg_qchgNegRlyCtr = VEWM_ConstB.Constant3;
    vewm_flg_PTCNegRlyCtr = VEWM_ConstB.Constant4;
}

/* Output and update for function-call system: '<S2>/VEWM' */
void VEWM_b(void)
{
    CurrSub();
    VEWM_B.LogicalOperator = (Rte_flg_SChgIgSts_GetVal() &&
        (Rte_enum_SChgCcSts_GetVal() != 0));
    VEWM_B.LogicalOperator1 = ((fltm_enum_hvilFlt == 3) ||
        (fltm_enum_ThermRunaway == 3));
    VEWMMgt();
    vewm_flg_negRlyCtr = VEWM_ConstB.Constant;
    vewm_flg_qchgRlyCtr = VEWM_ConstB.Constant1;
    vewm_flg_PTCRlyCtr = VEWM_ConstB.Constant2;
    vewm_flg_qchgNegRlyCtr = VEWM_ConstB.Constant3;
    vewm_flg_PTCNegRlyCtr = VEWM_ConstB.Constant4;
}

/* Model step function */
void TASK_VEWM(void)
{
    VEWM_b();
}

/* Model initialize function */
void VEWM_initialize(void)
{
    VEWM_Init();
}

/*
 * File trailer for generated code.
 *
 * [EOF]
 */
